package com.cn.por.util.sql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
/**
 * sql脚本执行工具类 
 * @author 26983
 *
 */
public class SqlUtils {
	/**
	 * 执行任意sql语句，返回成功或失败
	 * @param sql
	 * @return
	 * @throws SQLException
	 */
	public static boolean singleSql(String sql) throws SQLException {
		Connection connection = null;
		Statement statement = null;
		boolean result = false;
		try {
			connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/pro?user=root&password=123456&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&&allowPublicKeyRetrieval=true");
			statement = connection.createStatement();
			statement.execute(sql);
			result=true;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			connection.close();
			statement.close();
		}
		System.out.println(result);
		return result;
	} 
		
	public static void main(String[] args) throws SQLException {	
		SqlUtils.singleSql("INSERT INTO `menu`(`id`, `pattern`, `code`, `parent_code`, `sort_num`, `resource_type`, `path`, `component`, `redirect`, `name`, `title`, `hidden`, `icon`, `vali_flag`) VALUES (23, '/auto/index', '430301', '4303', 1, '1', '/auto/index', '/auto/index', NULL, 'Auto', '模块工程', '0', 'help', '1')");		
		//SqlUtils.singleSql("alter table menu add column icon varchar(48) default null comment \"图标\"");
		//SqlUtils.singleSql("alter table menu comment \"资源菜单表\"");
		//SqlUtils.singleSql("alter table menu add column path varchar(128) default null comment \"路径\"");
	}

}   
